prepare s2_http_header
pre '/* s^2 - hash HTTP header names'
pre '   Copyright (C) 2019 Ariadne Devos'
pre ''
pre '   This program is free software: you can redistribute it and/or modify'
pre '   it under the terms of the GNU General Public License as published by'
pre '   the Free Software Foundation, either version 3 of the License, or'
pre '   (at your option) any later version.'
pre ''
pre '   This program is distributed in the hope that it will be useful,'
pre '   but WITHOUT ANY WARRANTY; without even the implied warranty of'
pre '   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the'
pre '   GNU General Public License for more details.'
pre ''
pre '   You should have received a copy of the GNU General Public License'
pre '   along with this program.  If not, see <http://www.gnu.org/licenses/>. */'
pre ''
pre '#include <sHT/web/header.h>'

# (RFC 7540 (HTTP/2), 8.1.2 HTTP Header Fields, p. 35)
# ‘Just as in HTTP/1.x, header field names are strings of ASCII characters
# that are compared in a case-insensitive fashion. However, header field
# names MUST be converted to lowercase prior to their encoding in HTTP/2.’
#
# (RFC 2616 (HTTP/1.1), 4.2 Message Headers, p. 31)
# ‘Field names are case-insensitive’
#
# Therefore, internally always use lowercase, and in HTTP/1.1 mode, downcase
# all input. (TODO: gperf's %ignore-case option might be interesting.)

function entries() {
	local class="$1"
	local x
	local y
	shift
	for x in "$@"; do
		y="${x^^}"
		y="${y//-/_}"
		entry "${x,,}" "S2_HTTP_${class}_${y}"
	done
}

# (RFC 2616 (HTTP/1.1), 4.5 General Header Fields, p. 34-35)
# Applicable to both requests and responses.
# ‘Unrecognized header fields are treated as entity-header fields’
entries 'GENERAL' Cache-Control Connection Date Pragma Trailer \
  Transfer-Encoding Upgrade Via Warning

# (RFC 2616 (HTTP/1.1), 5.3 Request Header Fields, p. 38-39)
# Only for requests.
# ‘Unrecognized header fields are treated as entity-header fields’
entries 'REQUEST' Accept Accept-Charset Accept-Encoding Accept-Language \
  Authorization Expect From Host If-Match If-Modified-Since If-None-Match \
  If-Range If-Unmodified-Since Max-Forwards Proxy-Authorization Range Referer \
  TE User-Agent

# (RFC 2616 (HTTP/1.1), 6.2 Response Header Fields, p. 41-42)
# Only for responses.
# ‘Unrecognized header fields are treated as entity-header fields’
entries 'RESPONSE' Accept-Ranges Age ETag Location Proxy-Authenticate \
  Retry-After Server Vary WWW-Authenticate

# (RFC 2616 (HTTP/1.1), 7.1 Entity Header Fields, p. 42)
# For requests with a body (e.g. POST) or responses.
# E.g., about a PDF document for a resource requested via GET,
# or about an upload via POST.
#
# ‘Unrecognized header fields SHOULD be ignored by the recipient’
# ‘Unrecognized header fields MUST be forwarded by transparent proxies’
entries 'ENTITY' Allow Content-Encoding Content-Language Content-Length \
  Content-Location Content-MD5 Content-Range Content-Type Expires Last-Modified

solve
